#include <iostream>
#include <cstring>
using namespace std;
#define maxn 1000002
const double eps = 1e-6;

int n,m;
int maxroom[maxn];
int d[maxn], s[maxn], t[maxn];
int sum[maxn];

bool equal(double a, double b){
	if(a<b) swap(a,b);
	if(a-b>eps) return false;
	else return true;
}

bool check(int num){
	memset(sum, 0, sizeof(sum));
	for(int i=1; i<=num; i++){
		sum[s[i]] += d[i];
		sum[t[i]+1] -= d[i];
	}
	for(int i=1; i<=n; i++){
		sum[i] += sum[i-1];
		if(sum[i] > maxroom[i])
			return false;
	}
	return true;
}

int main(){
	cin>>n>>m;
	for(int i=1; i<=n; i++)
		cin>>maxroom[i];
	for(int j=1; j<=m; j++)
		cin>>d[j]>>s[j]>>t[j];
	
	double l=1, r=n+1, mid=0;
	while(!equal(r,l)){
		mid = (r+l)/2;
		if(check(mid)) l=mid;
		else r=mid;
	}
	
	if(!equal(l, n+1))
		cout<<"-1"<<endl<<l<<endl;
	else
		cout<<"0"<<endl;
	
	return 0;
}